package com.example.hp.yuejian5.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.hp.yuejian5.R;
import com.example.hp.yuejian5.RetrofitListener.RetrofitListener;
import com.example.hp.yuejian5.adapter.ShowAdapter;
import com.example.hp.yuejian5.bean.ShowBean;
import com.example.hp.yuejian5.model.ShowModel;

import java.util.ArrayList;
import java.util.List;

public class ShowFragment extends Fragment {
    private RecyclerView recyclerView;
    private List<ShowBean> list=new ArrayList<ShowBean>();
    private ShowAdapter showAdapter;
    private RecyclerView.LayoutManager layoutManager;
    public RetrofitListener<List<ShowBean>> listener;
    public ShowFragment() {
        // Required empty public constructor
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
        getshowlist();
    }
    private void initView(View v)
    {
        recyclerView=v.findViewById(R.id.show_recyclerview);
        layoutManager=new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        showAdapter=new ShowAdapter(getActivity());
        recyclerView.setAdapter(showAdapter);
    }

    private void getshowlist()
    {
        ShowModel showModel=new ShowModel();
        showModel.showList(listener);
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        listener=new RetrofitListener<List<ShowBean>>() {
            @Override
            public void onSuccess(List<ShowBean> list, int flag) {
                showAdapter.showData(list);
            }

            @Override
            public void onFail() {
                Toast.makeText(getActivity(),"获取失败",Toast.LENGTH_SHORT).show();
            }
        };
        return inflater.inflate(R.layout.fragment_show, container, false);
    }
}
